function flat(data) {
    function recurse(result, cur, prop) {
        if (Object(cur) !== cur) {
            result[prop] = cur;
        } else if ($.isArray(cur)) {
            for (var i = 0, l = cur.length; i < l; i++) {
            	result[i] = cur[i];
            	recurse(result[i], result[i], "");
            }
        } else {
            var isEmpty = true;
            for (var p in cur) {
                isEmpty = false;
                recurse(result, cur[p], prop ? prop + '_' + p : p);
            }
            if (isEmpty) {
                result[prop] = {};
            }
        }
    }

    var result = null;
    if ($.isArray(data)) {
    	result = []
    } else {
    	result = {};
    }
    recurse(result, data, "");
    return result;
};

